package com.ss.android.article.base.ui;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.AttributeSet;
import com.bytedance.common.utility.UIUtils;
import com.ss.android.article.common.NightModeAsyncImageView;

public class WatermarkImageView extends NightModeAsyncImageView {
    private Paint a;
    private Paint b;
    private RectF c;
    private int d;
    private float e;
    private int f;
    private int g;
    private float h;

    public WatermarkImageView(Context arg1) {
        super(arg1);
    }

    public WatermarkImageView(Context arg1, AttributeSet arg2) {
        super(arg1, arg2);
    }

    public WatermarkImageView(Context arg1, AttributeSet arg2, int arg3) {
        super(arg1, arg2, arg3);
    }

    private boolean a() {
        boolean v0 = (this.d & 2) != 0 ? true : false;
        return v0;
    }

    private boolean b(boolean arg9) {
        boolean v0 = false;
        if(this.a()) {
            if(this.a == null) {
                this.a = new Paint(1);
                this.a.setColor(-1);
                this.a.setTextSize(UIUtils.sp2px(this.getContext(), 10f));
                this.e = this.a.measureText("GIF");
                this.b = new Paint(1);
                this.b.setColor(-1308622848);
            }

            if(this.c == null || (arg9)) {
                this.h = UIUtils.dp2px(this.getContext(), 3f);
                this.f = this.getWidth();
                this.g = this.getHeight();
                float v2 = (((float)this.f)) - this.e - 2f * this.h;
                float v3 = (((float)this.g)) - UIUtils.dp2px(this.getContext(), 13f);
                if(this.c == null) {
                    this.c = new RectF(v2, v3, ((float)this.f), ((float)this.g));
                }
                else {
                    this.c.set(v2, v3, ((float)this.f), ((float)this.g));
                }
            }

            if(this.c.width() <= 0f) {
                return v0;
            }

            if(this.c.height() <= 0f) {
                return v0;
            }

            v0 = true;
        }

        return v0;
    }

    public void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        if(this.b(false)) {
            canvas.drawRect(this.c, this.b);
            canvas.drawText("GIF", this.c.left + this.h, (((float)this.g)) - this.h, this.a);
//            arg5.save(31);
            canvas.save();
            canvas.restore();
        }
    }

    protected void onSizeChanged(int arg2, int arg3, int arg4, int arg5) {
        super.onSizeChanged(arg2, arg3, arg4, arg5);
        if((arg2 != arg4 || arg3 != arg5) && (this.a())) {
            this.b(true);
        }
    }

    public void setWatermarkFlag(int arg1) {
        this.d = arg1;
    }
}

